const zlib = require('zlib');
const http = require('http');

const server = http.createServer((req, res) => {
    if (req.method === 'GET' && req.url === '/') {
        let result = "你好世界\n".repeat(10000);

        // 设置响应头为 deflate 编码
        res.setHeader('Content-Encoding', 'gzip')
        res.setHeader('Content-type', 'text/plan;charset=utf-8')

        // 压缩结果
        result = zlib.gzipSync(result);
        res.end(result)
    }
})

server.listen(3000, () => {
    console.log('server is running at http://localhost:3000')
})